package ${package.Controller};

import org.springframework.web.bind.annotation.RequestMapping;
import com.soviet.boot.common.annotation.ResultAndLog;
import com.soviet.boot.common.base.vo.IdsRequestVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
import lombok.AllArgsConstructor;
<#if auth>
import org.springframework.security.access.prepost.PreAuthorize;
</#if>
import org.springframework.web.bind.annotation.*;
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@AllArgsConstructor
@ResultAndLog
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>manager/${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>
    private final I${entity}Service ${table.entityPath}Service;

    /**
    * 分页查询
    *
    * @param page 分页对象
    * @return
    */
    @GetMapping("/page")
    public Object get${entity}Page(Page<${entity}> page, ${entity} query, @RequestParam(value = "dateRange", required = false) String dateRange) {
        return ${table.entityPath}Service.page(page, new LambdaQueryWrapper<>(query));
    }

    /**
    * 通过id查询${table.comment!}
    *
    * @param id id
    * @return Object
    */
    @GetMapping("/info")
    public Object getById(@RequestParam("id") Long id) {
        return ${table.entityPath}Service.getById(id);
    }

    /**
    * 新增${table.comment!}
    *
    * @param ${table.entityPath} ${table.comment!}
    * @return Object
    */
    @PostMapping("/add")
    <#if auth>
    @PreAuthorize("@pms.hasPermission('${package.ModuleName}:${table.entityPath}:add')")
    </#if>
    public Object save(@RequestBody ${entity} ${table.entityPath}) {
        return ${table.entityPath}Service.save(${table.entityPath});
    }

    /**
    * 修改${table.comment!}
    *
    * @param ${table.entityPath} ${table.comment!}
    * @return Object
    */
    @PostMapping("/update")
    <#if auth>
    @PreAuthorize("@pms.hasPermission('${package.ModuleName}:${table.entityPath}:edit')")
    </#if>
    public Object updateById(@RequestBody ${entity} ${table.entityPath}) {
        return ${table.entityPath}Service.updateById(${table.entityPath});
    }

    /**
    * 通过id删除${table.comment!}
    *
    * @param id id
    * @return Object
    */
    @PostMapping("/delete")
    <#if auth>
    @PreAuthorize("@pms.hasPermission('${package.ModuleName}:${table.entityPath}:del')")
    </#if>
    public Object removeById(@RequestParam Long id) {
        return ${table.entityPath}Service.removeById(id);
    }


    /**
    * 批量删除${table.comment!}
    *
    * @param body ids
    * @return Object
    */
    @PostMapping("/batchDelete")
    <#if auth>
    @PreAuthorize("@pms.hasPermission('${package.ModuleName}:${table.entityPath}:del')")
    </#if>
    public Object removeByIds(@RequestBody IdsRequestVO body) {
        return ${table.entityPath}Service.removeByIds(body.getIds());
    }

}
</#if>




